package ThreadTest;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

class NewTread implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+": "+i);
        }
    }
}

public class TreadPool {
    public static void main(String[] args) {
        //1.提供指定线程数量的线程池
        ExecutorService pool = Executors.newFixedThreadPool(10);
        ThreadPoolExecutor service = (ThreadPoolExecutor) pool;
        //设置线程池的属性
        service.setCorePoolSize(15);  //线程数

        //2.执行指定的线程的操作。需要提供实现Runnable接口或Callable接口实现类的对象
        pool.execute(new NewTread());//适合用于Runnable
        //pool.submit();//适合用于Callable
        //3.关闭连接池
        pool.shutdown();
    }
}
